package com.ruoyi.web.controller.applet;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.system.domain.dto.WeChatLoginDto;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 微信登录
 */
@RequestMapping("/applet")
@RestController
public class AppletLoginController {

    @Autowired
    private SysLoginService loginService;

    @Autowired
    private ISysUserService iSysUserService;

    /**
     * 微信一键登录
     *
     * @param dto 登录信息
     * @return 结果
     */
    @PostMapping("/weChatLogin")
    public AjaxResult weChatLogin(@RequestBody WeChatLoginDto dto) {
        return AjaxResult.success(loginService.weChatLogin(dto));
    }

    /**
     * 修改用户头像跟昵称
     * @param user
     * @return
     */
    @PostMapping("/updateUserInfo")
    public AjaxResult updateUserInfo(@RequestBody SysUser user)
    {
        user.setUserId(SecurityUtils.getUserId());
        return AjaxResult.success(iSysUserService.updateUserInfo(user));
    }

    /**
     * 获取用户信息
     *
     * @return 用户信息
     */
    @GetMapping("getInfo")
    public AjaxResult getInfo()
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("user", iSysUserService.selectUserById(SecurityUtils.getUserId()));
        return ajax;
    }

}
